package com.yb0os1.controller.admin;

import com.yb0os1.dto.OrderCancelDTO;
import com.yb0os1.dto.OrderConditionSearchDTO;
import com.yb0os1.dto.OrderRejectDTO;
import com.yb0os1.result.PageResult;
import com.yb0os1.result.Result;
import com.yb0os1.serve.OrderServe;
import com.yb0os1.vo.OrderStatisticsVO;
import com.yb0os1.vo.OrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Tag(name = "管理员处理订单的操作")
public class OrderController {
    @Autowired
    private OrderServe orderServe;

    @Operation(summary = "查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getOrderDetails(@PathVariable Long id){
        return Result.success(orderServe.getOrderById(id));
    }

    @Operation(summary = "订单搜素")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrderConditionSearchDTO orderConditionSearchDTO){
        log.info("接受的参数{}",orderConditionSearchDTO);
        return Result.success(orderServe.conditionSearch(orderConditionSearchDTO));
    }

    @Operation(summary = "接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrderRejectDTO orderRejectDTO){
        orderServe.confirmOrder(orderRejectDTO.getId());
        return Result.success();
    }

    @Operation(summary = "拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrderRejectDTO orderRejectDTO){
        log.info("拒单参数{}",orderRejectDTO);
        orderServe.rejectionOrder(orderRejectDTO);
        return Result.success();
    }

    @Operation(summary = "派送订单")
    @PutMapping("/delivery/{id}")
    public Result sendOrder(@PathVariable Long id){
        orderServe.sendOrder(id);
        return Result.success();
    }

    @Operation(summary = "取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrderCancelDTO orderCancelDTO){
        orderServe.cancelOrder(orderCancelDTO);
        return Result.success();
    }

    @Operation(summary = "各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics(){
        return Result.success(orderServe.orderStatistics());
    }
    @Operation(summary = "完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id){
        orderServe.completeOrder(id);
        return Result.success();
    }
}
